package adfc2.render3d.mesh;

import adfc2.render3d.IRenderable;
import adfc2.render3d.TextureReference;

/**
 * Примитив --- прямоугольная горизонтальная рамка
 */
public class Frame extends Mesh {

    /**
     * @param xyz       Координаты левого ближнего нижнего угла
     * @param size      Размеры по x,y,z
     * @param thickness Толщина рамки
     */
    public Frame(double[] color, double[] xyz, double[] size, double thickness, TextureReference texture) {
        super(primitivesFor(color, xyz, size, thickness, texture));
    }


    private static IRenderable[] primitivesFor(double[] color, double[] xyz, double[] size, double thickness, TextureReference texture) {
        IRenderable[] primitives = new IRenderable[4];
        primitives[0] = new Box(color,
                new double[]{xyz[0], xyz[1], xyz[2]},
                new double[]{thickness, size[1] - thickness, size[2]}, texture);
        primitives[1] = new Box(color,
                new double[]{xyz[0] + thickness, xyz[1], xyz[2]},
                new double[]{size[0] - thickness, thickness, size[2]}, texture);
        primitives[2] = new Box(color,
                new double[]{xyz[0] + size[0] - thickness, xyz[1] + thickness, xyz[2]},
                new double[]{thickness, size[1] - thickness, size[2]}, texture);
        primitives[3] = new Box(color,
                new double[]{xyz[0], xyz[1] + size[1] - thickness, xyz[2]},
                new double[]{size[0] - thickness, thickness, size[2]}, texture);
        return primitives;
    }
}
